package cn.tedu.knows.portal.mapper;

import cn.tedu.knows.portal.model.Question;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author tedu.cn
 * @since 2021-10-27
 */
@Repository
public interface QuestionMapper extends BaseMapper<Question> {
    //根据用户id查询问题数
    @Select("select count(*) from question where user_id=#{id}")
    int countQuestionByUserId(Integer userId);


    @Select("select count(*) from user_collect where user_id = #{id}")
    int countCollectByUserId(Integer userId);



    //查询讲师问题列表
    @Select("select q.* from question q  left join user_question \n" +
            "uq on q.id = uq.question_id where uq.user_id=#{id} or\n" +
            "q.user_id=#{id} order by q.createtime desc")
    List<Question> findTeacherQuestion(Integer userId);

    //修改问题状态的sql语句
    @Update("update question set status=#{status} where id=#{questionId}")
    int updateStatus(@Param("status") Integer status,
                     @Param("questionId") Integer questionId);

}
